package com.gitee.wsl.doc.prosemirror.model.node.ext

import com.gitee.wsl.doc.prosemirror.model.mark.Mark
import com.gitee.wsl.doc.prosemirror.model.mark.MarkType
import com.gitee.wsl.doc.prosemirror.model.node.Node
import com.gitee.wsl.doc.prosemirror.state.selection.Selection

fun Node.getMarksOfTypeInRange(selection: Selection, type: MarkType): List<Mark>{
    val doc = this
    val from = selection.from
    val to = selection.to
    val marks = mutableListOf<Mark>()

    doc.nodesBetween(from, to) { node, pos, parent, index ->
        node.marks.forEach { mark ->
            if (mark.type == type) {
                marks.add(mark)
            }
        }
        true
    }

    return marks
}